var mobId, mob, stats;
var 清怪 = true;
var 刷新地图 = true;
var 复活次数 = 11;
var 副本名称 = "组队任务_罗朱";
var BOSS_1_id = 9300106;
var BOSS_1_血量倍率 = 60;
var 副本时限 = 1000 * 60 * 40;
var 实例地图 = [925100000, 925100100, 925100200, 925100201, 925100202, 925100300, 925100301, 925100302, 925100400, 925100500, 925100600, 925100700];
var 准备地图 = 251010404;
var 退场倒计时 = 40;

function init() {}

function setup(g, b) {
    em.getProperties().clear();
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    em.setProperty("stage925100200", "0");
    em.setProperty("stage2a", "0");
    em.setProperty("stage925100300", "0");
    em.setProperty("stage3a", "0");
    em.setProperty("stage2", "0");
    var d = em.newInstance(副本名称);
    for (var c = 0; c < 实例地图.length; c++) {
        var f = d.setInstanceMap(实例地图[c]);
        f.resetPQ(g);
        f.resetFully();
        f.killAllMonsters(清怪);
        f.respawn(刷新地图)
    }
    d.startEventTimer(副本时限);
    d.setProperty("FBtime", 副本时限);
    d.setProperty("FBname", 副本名称);
    d.setProperty("strMap", 准备地图);
    var e = em.getMonster(BOSS_1_id).getMobMaxHp() * BOSS_1_血量倍率;
    d.setProperty("BOSShp", e);
    mobId = 9300106;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = 999999999;
    mob.getChangedStats().mp = 99000000;
    mob.setSize(300);
    mob.getChangedStats().matk = 50;
    mob.getChangedStats().watk = 50;
    mob.getChangedStats().acc = 9999999;
    mob.getChangedStats().level = 150;
    mob.heal();
    d.registerMonster(mob);
    var a = d.getMapInstance(实例地图[9]);
    a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(625, 238));
    return d
}

function onItemPickedUp(f, h, g) {
    var c = 0;
    var b = p.getMapId();
    if (b == 925100100) {
        c = 20
    }
    if (g == 4001260) {
        var e = h.getAPI().getJobName(h.getAPI().getJob());
        var a = h.getName();
        f.getPlayers().forEach(function (j) {
            j.getAPI().getTopMsgFont("" + e + "<" + a + ">捡到1个禁忌之枪，快交给队长吧。", 3, 20, 13, 0)
        })
    } else {
        if (g == 4001117) {
            var e = h.getAPI().getJobName(h.getAPI().getJob());
            var a = h.getName();
            f.getPlayers().forEach(function (j) {
                j.getAPI().getTopMsgFont("" + e + "<" + a + ">捡到1个骷髅钥匙，快交给队长吧。", 3, 20, 13, 0)
            })
        } else {
            if (g == 4001120) {
                var d = 0;
                f.getPlayers().forEach(function (j) {
                    d += j.getAPI().getItemQuantity(4001120)
                });
                var i = c - d;
                var e = h.getAPI().getJobName(h.getAPI().getJob());
                var a = h.getName();
                if (d >= c) {
                    f.getPlayers().forEach(function (j) {
                        j.getAPI().fieldEffect_ScreenMsg("quest/party/clear");
                        j.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100);
                        j.getAPI().fieldEffect_SetObjectState(100, "gate");
                        j.getAPI().removeAll(4001120);
                        j.getAPI().playerMessage(-1, "通往下一关的传送口打开了。")
                    });
                    em.setProperty("stage2", "1")
                } else {
                    f.getPlayers().forEach(function (j) {
                        j.getAPI().getTopMsgFont("" + e + "<" + a + ">在『" + mapName + "』找到第" + (d) + "张初级证明。", 3, 20, 13, 0);
                        j.getAPI().showMapEffect(true, 5120018, "还差" + i + "张初级证明通关。", 15, false)
                    })
                }
            } else {
                if (g == 4001121) {
                    var d = 0;
                    f.getPlayers().forEach(function (j) {
                        d += j.getAPI().getItemQuantity(4001121)
                    });
                    var i = c - d;
                    var e = h.getAPI().getJobName(h.getAPI().getJob());
                    var a = h.getName();
                    if (d >= c) {
                        f.getPlayers().forEach(function (j) {
                            j.getAPI().fieldEffect_ScreenMsg("quest/party/clear");
                            j.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100);
                            j.getAPI().fieldEffect_SetObjectState(100, "gate");
                            j.getAPI().removeAll(4001121);
                            j.getAPI().playerMessage(-1, "通往下一关的传送口打开了。")
                        });
                        em.setProperty("stage2", "2")
                    } else {
                        f.getPlayers().forEach(function (j) {
                            j.getAPI().getTopMsgFont("" + e + "<" + a + ">在『" + mapName + "』找到第" + (d) + "张中级证明。", 3, 20, 13, 0);
                            j.getAPI().showMapEffect(true, 5120018, "还差" + i + "张中级证明通关。", 15, false)
                        })
                    }
                } else {
                    if (g == 4001122) {
                        var d = 0;
                        f.getPlayers().forEach(function (j) {
                            d += j.getAPI().getItemQuantity(4001122)
                        });
                        var i = c - d;
                        var e = h.getAPI().getJobName(h.getAPI().getJob());
                        var a = h.getName();
                        if (d >= c) {
                            f.getPlayers().forEach(function (j) {
                                j.getAPI().fieldEffect_ScreenMsg("quest/party/clear");
                                j.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100);
                                j.getAPI().fieldEffect_SetObjectState(100, "gate");
                                j.getAPI().removeAll(4001122);
                                j.getAPI().playerMessage(-1, "通往下一关的传送口打开了。")
                            });
                            em.setProperty("stage2", "3")
                        } else {
                            f.getPlayers().forEach(function (j) {
                                j.getAPI().getTopMsgFont("" + e + "<" + a + ">在『" + mapName + "』找到第" + (d) + "张高级证明。", 3, 20, 13, 0);
                                j.getAPI().showMapEffect(true, 5120018, "还差" + i + "张高级证明通关。", 15, false)
                            })
                        }
                    }
                }
            }
        }
    }
}

function WarpTask(b, a) {
    player.scheduleWarpTask(4, b, a, false)
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(实例地图[0]);
    a.dropMessage(6, "[" + 副本名称 + "] 进入到了挑战地图，请小心行事。");
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(复活次数);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0);
    a.tryPartyQuest(1203)
}

function onPlayerKilled(b, a) {}

function onPlayerRevived(b, a) {
    if (a.getReviveCount() > 0) {
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onMapChanged(d, c, b) {
    var a = 实例地图.indexOf(b);
    if (a < 0) {
        on玩家退场(d, c, false);
        return
    }
    switch (a) {
        case 0:
            break;
        case 1:
            em.setProperty("stage2", "0");
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        case 6:
            break;
        case 7:
            break;
        case 8:
            break;
        case 9:
            break;
        case 10:
            break;
        case 11:
            break;
        default:
            break
    }
}

function onMonsterKilled(b, c) {
    if (c == 9300106) {
        openNpc(b, 9130027, "评价系统");
        for (var a = 0; a < b.getPlayerCount(); a++) {
            b.getPlayers().get(a).dropMessage(6, "[" + 副本名称 + "] 成功击杀BOSS！")
        }
        b.getPlayers().forEach(function (e) {
            e.scheduleWarpTask(5, 准备地图, 0, false);
            e.getAPI().gainItem(5062024, 1);
            e.getAPI().gainItem(5062500, 2);
            e.getAPI().gainItem(5062010, 2)
        })
    } else {
        var d = p.getMapId();
        if (d == 925100201) {
            if (player.getMap().getNumMonsters() == 0) {
                b.getPlayers().forEach(function (e) {
                    e.getAPI().fieldEffect_ScreenMsg("monsterPark/clear");
                    e.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100);
                    e.getAPI().gainItem(4031437, 1)
                });
                player.getAPI().getMap().setReactorState();
                em.setProperty("stage2a", "1");
                player.getAPI().addPopupSay(2094002, 4000, "捡到一把[老海盗的箱子钥匙]，快打开中间的宝物箱吧。")
            } else {
                b.getPlayers().forEach(function (e) {
                    e.getAPI().playerMessage(-1, "怪物还剩" + e.getMap().getNumMonsters() + "个。")
                })
            }
        } else {
            if (d == 925100301) {
                if (player.getMap().getNumMonsters() == 0) {
                    b.getPlayers().forEach(function (e) {
                        e.getAPI().fieldEffect_ScreenMsg("monsterPark/clear");
                        e.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100);
                        e.getAPI().gainItem(4031437, 1)
                    });
                    player.getAPI().getMap().setReactorState();
                    em.setProperty("stage3a", "1");
                    player.getAPI().addPopupSay(2094002, 4000, "捡到一把[老海盗的箱子钥匙]，快打开中间的宝物箱吧。")
                } else {
                    b.getPlayers().forEach(function (e) {
                        e.getAPI().playerMessage(-1, "怪物还剩" + e.getMap().getNumMonsters() + "个。")
                    })
                }
            }
        }
    }
    return 1
}

function onMonsterDamaged(b, a, d, e, c) {
    if (d == BOSS_1_id) {
        a.getAPI().addNumberForQuestInfo(准备地图, "damage", e)
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function initPropArrayRandom(a, d, j, b, h) {
    var g = new Array();
    var k = h - b + 1;
    var c = (j - d) < (h - b) ? true : false;
    do {
        var f = randomNum(d, j);
        if (c || g.indexOf(f) < 0) {
            g.push(f);
            k--
        }
    } while (k);
    for (var e = b; e <= h; e++) {
        if (em.getProperty(a + "_" + e) == null) {
            em.setProperty(a + "_" + e, g[e - 1])
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPartyDisbanded(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, true);
    return 0
};